﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace f方法练习
{
    internal class Program
    {
        public static bool IsOdd(int number)
        {
            return number % 2 == 1 ? true : false;
        }
        public static int Max(int i1, int i2)
        {
            return i1 > i2 ? i1 : i2;
        }

        public static int ArrayMax(int[] ints)
        {
            int max = 0;
            foreach(int i in ints)
            {
                if(i > max) max = i;
            }
            return max;
        }

        public static int Sum(int[] ints)
        {
            int sum = 0;
            foreach(var i in ints)
                sum += i;
            return sum;
        }

        public static int Avg(int[] ints)
        {
            return Sum(ints) / ints.Length;
        }

        public static string JoinString(string[] names)
        {
            string res = null;
            for(int i = 0; i < names.Length; i++)
            {
                if(i == names.Length - 1)
                {
                    res += names[i];
                }
                else if(i < names.Length - 1)
                {
                    res += names[i];
                    res += '|';
                }
            }
            return res;
        }

        public static void FindNumber(int[] nums, out int max, out int min)
        {
            max = int.MinValue;
            min = int.MaxValue;
            foreach(var i in  nums)
            {
                if(i > max)
                {
                    max = i;
                }
                if(i < min)
                {
                    min = i;
                }
            }
            Console.WriteLine(max);
            Console.WriteLine(min);
        }

        public static void Sort(ref int[] nums)
        {
            for(int i = 0; i < nums.Length - 1; i++)
            {
                for(int j = 0; j < nums.Length - 1 - i; j++)
                {
                    //升序排序
                    if (nums[j] > nums[j + 1])
                    {
                        int tmp = nums[j];
                        nums[j] = nums[j + 1];
                        nums[j + 1] = tmp;
                    }
                }
            }
        }

        public static void GetLevel(int score)
        {
            if(score >= 80 && score <= 100)
            {
                Console.WriteLine("优");
            }
            else if(score >= 60 &&  score <= 79)
            {
                Console.WriteLine("良");
            }
            else
            {
                Console.WriteLine("差");
            }
        }

        public static void Reverse(ref string[] strs)
        {
            for(int i = 0; i < strs.Length / 2; i++)
            {
                string tmp = strs[i];
                strs[i] = strs[strs.Length - 1 - i];
                strs[strs.Length - i - 1] = tmp;
            }
        }

        public static void ShowResult()
        {
            int index = 0;
            int[] nums = new int[2];
            while(true)
            {
                Console.WriteLine($"\n请输入第{index + 1}个数字: ");
                string num = Console.ReadLine();

                int result;
                bool flag = int.TryParse(num, out result);

                if(!flag)
                {
                    Console.WriteLine($"输入的第{index + 1}个数不是数字，请重新输入:");
                    continue;
                }
                nums[index] = result;
                index++;

                if(index == 2)
                {
                    if (nums[0] < nums[1])
                    {
                        Console.WriteLine($"输入的第1个数{nums[0]}小于第2个数{nums[1]}，请重新输入");
                        index = 0;
                        continue ;
                    }
                    Console.WriteLine($"输入的第个数{nums[0]}小于第2个数{nums[1]}，符合要求");
                    break;
                }
            }
            
            
        }
        static void Main(string[] args)
        {
            //int a1 = 10;
            //int b1 = 20;
            //Console.WriteLine(Max(a1, b1));

            //int[] arr = { 29, 42, 64, 13, 67, 89 };
            //Console.WriteLine(ArrayMax(arr));

            //int[] arr = { 29, 42, 64, 13, 67, 89 };
            //Console.WriteLine(Sum(arr));

            //int[] arr = { 29, 42, 64, 13, 67, 89 };
            //Console.WriteLine(Avg(arr));

            //int n = 0;
            //while(true)
            //{
            //    Console.WriteLine("请输入数字: ");
            //    n = Convert.ToInt32(Console.ReadLine());
            //    if (IsOdd(n))
            //    {
            //        Console.WriteLine($"输入的{n}是奇数");
            //        break;
            //    }
            //}

            //string[] names = { "梅西", "卡卡", "郑大世" };
            //Console.WriteLine(JoinString(names));

            //int max;
            //int min;
            //int[] nums = { 2, 32, 45, 28, 67, 26, 69 };
            //FindNumber(nums, out max, out min);

            //int[] ints = { 1, 3, 5, 7, 90, 2, 4, 6, 8, 10 };
            //Sort(ref ints);
            //foreach(int i in ints)
            //{
            //    Console.Write($"{i} ");
            //}
            //Console.WriteLine();

            //int score = Convert.ToInt32(Console.ReadLine());
            //GetLevel(score);

            //string[] strs = { "中国", "韩国", "美国", "日本" };
            //Reverse(ref strs);
            //foreach(string str in strs)
            //{
            //    Console.Write(str + " ");
            //}
            //Console.WriteLine();

            ShowResult();
        }
    }
}
